
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <link rel="apple-touch-icon" sizes="76x76" href="./assets/img/favicon.ico">
    <link rel="icon" type="image/png" href="./assets/img/favicon.ico">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>数据资产管理平台</title>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no'
        name='viewport' />



    <!-- Main CSS -->
    <link href="./assets/css/main.css" rel="stylesheet" />
    <link href="./assets/layui/css/layui.css" rel="stylesheet">
    <!-- Animation CSS -->
    <link href="vendor/aos.css" rel="stylesheet" />
    <style>
        .inputCode {
            width: 200px;
            padding: .5em;

        }
    </style>

</head>

<body>
    <section class="pt-4 pb-5">
        <div class="col-md-12" id="probation">
            <form id="form1" class="layui-form" lay-filter="productRegisterForm" >
                <div class="definition selShow">
					<div class="layui-form-item">
					    <label class="layui-form-label" style="width: 100px;">用户：</label>
					    <div class="layui-input-block" style="margin-left: 120px;">
					      <select name="selectUsers" lay-filter="selectUsers" id="selectUsers">
					        <option value="">请选择</option>
					      </select>
					    </div>
					  </div>
                </div>
                <div class="layui-form-item">
                    <div class="">
                        <label class="layui-form-label" style="width: 100px;">授权码：</label>
                        <div class="layui-input-block" style="margin-left: 120px;" >
                        <input id="kew" type="text" value="" placeholder="请输入授权码" name="keyword" class="form-control">
                        </div>
                    </div>
                </div>
            </form>
            <button class="btn btn-sm btn-cyan btn-round text-white mt-3" id="saveForm">提交</button>
        </div>
    </section>

    <script src="vendor/jquery.min.js" type="text/javascript"></script>
    <script src="vendor/popper.min.js" type="text/javascript"></script>
    <script src="vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="js/functions.js" type="text/javascript"></script>
    <script src="./assets/layui/layui.js" type="text/javascript"></script>
    <script src="js/tool.js" type="text/javascript"></script>
    <!-- Animation -->
    <script src="vendor/aos.js" type="text/javascript"></script>
    <noscript>
        <style>
            *[data-aos] {
                display: block !important;
                opacity: 1 !important;
                visibility: visible !important;
            }
        </style>
    </noscript>
    <script>
        AOS.init({
            duration: 700
        });
    </script>

    <!-- Disable animation on less than 1200px, change value if you like -->
    <script>
        AOS.init({
            disable: function () {
                var maxWidth = 1200;
                return window.innerWidth < maxWidth;
            }
        });
    </script>
    <script>
		let userInfo = sessionStorage.getItem('UserInfo');
		if(userInfo){
			userInfo = JSON.parse(userInfo);
			$("#userName").text(userInfo.userName);
		}
        // 判断授权验证是否通过
        let VerifyStatus = false
        // 授权的相关操作
        $('#proxyReg').on('click', function (e) {
            // 授权码框变为可选且自动聚焦
            $('.inputCode').removeAttr('disabled').focus();
        })
		 // 验证授权码是否正确
		$('#valid').on('click', function (e) {
		    e.preventDefault()
		    let valid = $('.inputCode').val();
		    if (valid) {
				$.ajax({
                   timeout:30000,
					url:window.Http+"/auth/code/operate",
					type:'POST',
					headers: {
					　　'Authorization':"Bearer "+sessionStorage.getItem('Token')
					},
					data:JSON.stringify({"operateType":1,"authCode":valid,"authType":2}),
					contentType: 'application/json;charset=utf-8',
					success:function (res){
						if(res.code === 200){
							VerifyStatus = true;
							$('#res').html('验证通过').attr('style','font-size: 12px;color: skyblue;width: 165px;display: inline-block;');
						}else{
							VerifyStatus = false;
							$('#res').html('验证失败：'+res.msg).attr('style','font-size: 12px;color: red;width: 165px;display: inline-block;');
						}
					}
				})
		    } else {
		        VerifyStatus = false
		        $('#res').html('验证失败,请填写授权码').attr('style','font-size: 12px;color: red;width: 165px;display: inline-block;');
		    }
		})
        // 提交注册信息
        $(function () {
            $('#reg').on('click', function (e) {
                e.preventDefault();
                let reg = $("input[name='register']:checked").val();

                if (reg == 'proxyReg') {
                    if (res == true) {
                        // 代理注册
                        alert('注册成功')
                    } else {
                        alert('请先进行授权')
                    }
                } else if (reg == null) {
                    alert('请选择注册方式')
                } else if (reg == 'ownReg') {
                    // 用户注册
                    //alert('注册成功')
					window.parent.location.href = "./dataSourceRegister.html";
                }
            })
        })
    </script>
    <script>
        //添加选择用户列表
        $(function(){
            console.log(window.Http)
            $.ajax({
            timeout:30000,
			url: window.Http + "/system/user/list/select",
			type: 'GET',
			headers: {
				'Authorization': "Bearer " + sessionStorage.getItem('Token')
			},
			data:{userName:""},
			success: function (res) {
				console.log(res)
				if (res.code === 200) {
					$("#selectUsers ").empty();
					if (res.rows && res.rows.length > 0) {
						let html = `<option value="">所有人</option>`;
						res.rows.forEach(function (val, index) {
							html += `<option value="${val.userId}">${val.nickName}</option>`
						})
						$("#selectUsers ").append(html);
					}else{
						let html = `<option value="">所有人</option>`
						$("#selectUsers ").append(html);
					}
					layui.form.render();
				}
			}
		})
        //提交
        $("body").on("click",'#saveForm',function (e){
            e.preventDefault();
           let a = $('#selectUsers').val();
           let b = $('#kew').val();
           let c = {
            "authUserId":+a,
            "authCode":b,
           };
           console.log(c);
           $.ajax({
           timeout:30000,
			url: window.Http + "/auth/code",
			type: 'POST',
			headers: {
				'Authorization': "Bearer " + sessionStorage.getItem('Token')
			},
			data: JSON.stringify(c),
			contentType:"application/json",
			success: function (res) {
				if (res.code === 200) {
					layer.msg("操作成功");
					setTimeout(function(){
						let index = parent.layer.getFrameIndex(window.name);
						//再执行关闭
						parent.layer.close(index);
						//parent.layer.close(1); //再执行关闭
					},1000)
				}else if(res.msg){
					layer.msg(res.msg);
				}else{
					layer.msg("操作失败");
				}
			}
		})
        })
        // 上传
        })

    </script>
</body>

</html>
